﻿var ProductQuery = function(rHd){
    var __hd = (typeof(rHd)=="string")?rHd:"productQuery";
    var __cField = null;
    var __mField = null;
    var __atlField = null;
    var __urlPath = null;
    var __goNewUrl = function(){
        var _url  = __urlPath;
        _url += "&cid="+__cField.value;
        //atl query can't with market query!!
        //_url += "&mid="+__mField.value;
        _url += "&atl="+__atlField.value;
        window.location.href = _url;
    };
    
    this.deploy = function(rUrlPath,rCategoryFieldId,rMarketFieldId,rAtlFieldId){
        __urlPath = (rUrlPath.indexOf("?")==-1)?rUrlPath+"?q=1":rUrlPath;
        __cField = $("#"+rCategoryFieldId);
        __mField = $("#"+rMarketFieldId);
        __atlField = $("#"+rAtlFieldId);
    };
    
    this.selectAtl = function(rAtlKey,rAtlData){
        if(typeof(rAtlKey)=="string" && rAtlKey!=""){
            var _val = __atlField.value;
            if(_val==''){
                _val += rAtlKey+","+rAtlData;
            }else{
                _val += "|"+rAtlKey+","+rAtlData;
            }
            __atlField.value = _val;
        }
        __goNewUrl();
    };
    
    this.removeAtl = function(rAtlKey,rAtlData){
        var val = __atlField.value; 
        val = val.replace(rAtlKey+","+rAtlData,"");
        val = val.replace(/\|\|/gi,"");
        __atlField.value = val;
        val = null;
        __goNewUrl();
    };
};